package com.ruoyi.comprehensive.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.comprehensive.domain.ReceiveVisits;
import com.ruoyi.comprehensive.service.IReceiveVisitsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 接访信息Controller
 *
 * @author ruoyi
 * @date 2021-09-01
 */
@RestController
@RequestMapping("/comprehensive/visits")
public class ReceiveVisitsController extends BaseController {
    @Autowired
    private IReceiveVisitsService receiveVisitsService;

    /**
     * 查询接访信息列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:visits:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReceiveVisits receiveVisits) {
        startPage();
        List<ReceiveVisits> list = receiveVisitsService.selectReceiveVisitsList(receiveVisits);
        return getDataTable(list);
    }

    /**
     * 导出接访信息列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:visits:export')")
    @Log(title = "接访信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReceiveVisits receiveVisits) {
        List<ReceiveVisits> list = receiveVisitsService.selectReceiveVisitsList(receiveVisits);
        ExcelUtil<ReceiveVisits> util = new ExcelUtil<ReceiveVisits>(ReceiveVisits.class);
        return util.exportExcel(list, "接访信息数据");
    }

    /**
     * 获取接访信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:visits:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(receiveVisitsService.selectReceiveVisitsById(id));
    }

    /**
     * 新增接访信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:visits:add')")
    @Log(title = "接访信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReceiveVisits receiveVisits) {
        return toAjax(receiveVisitsService.insertReceiveVisits(receiveVisits));
    }

    /**
     * 修改接访信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:visits:edit')")
    @Log(title = "接访信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReceiveVisits receiveVisits) {
        return toAjax(receiveVisitsService.updateReceiveVisits(receiveVisits));
    }

    /**
     * 删除接访信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:visits:remove')")
    @Log(title = "接访信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(receiveVisitsService.deleteReceiveVisitsByIds(ids));
    }
}
